program Geometrie2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  x1, y1, x2, y2, x3, y3, x4, y4: Integer;
  d1, d2, a1, a2, b1, b2, c1, c2, xp1, yp1, xp2, yp2, x0, y0, r: Real;
  inp: TextFile;

begin
  AssignFile(inp, 'inputg2.txt');
  Reset(inp);
  Read (inp, x1);
  Read (inp, y1);
  Read (inp, x2);
  Read (inp, y2);
  Read (inp, x3);
  Read (inp, y3);
  Read (inp, x4);
  Read (inp, y4);
  a1:=y1-y2;
  b1:=x2-x1;
  c1:=x1*y2-x2*y1;
  a2:=y3-y4;
  b2:=x4-x3;
  c2:=x3*y4-x4*y3;
  x0:=(b1*a1*c2-c1*a1*b2)/(a1*(a1*b2-a2*b1));
  y0:=(c2*a1-a2*c1)/(a2*b1-b2*a1);
  if ((x2-x1)*(x0-x1) >= 0) and ((y2-y1)*(y0-y1) >= 0) and ((x4-x3)*(x0-x3) >= 0) and ((y4-y3)*(y0-y3) >= 0) then
  begin
    r:=0;
  end else begin
    d1:=(a1*x3+b1*y3+c1)/(sqrt(a1*a1+b1*b1));
    xp1:=x3-(a1*d1/((sqrt(a1*a1+b1*b1))));
    yp1:=y3-(b1*d1/((sqrt(a1*a1+b1*b1))));
    d2:=(a2*x1+b2*y1+c2)/(sqrt(a2*a2+b2*b2));
    xp2:=x1-(a2*d2/((sqrt(a2*a2+b2*b2))));
    yp2:=y1-(b2*d2/((sqrt(a2*a2+b2*b2))));
    if (((x4-x3)*(xp1-x3) >= 0) and ((y4-y3)*(yp1-y3) >= 0)) or (((x2-x1)*(xp2-x1) >= 0) and ((y2-y1)*(yp2-y1) >= 0)) then
    begin
      if ((x4-x3)*(xp1-x3) >= 0) and ((y4-y3)*(yp1-y3) >= 0) then
      begin
        r:=sqrt((x1-xp1)*(x1-xp1)+(y1-yp1)*(y1-yp1));
      end;
      if ((x2-x1)*(xp2-x1) >= 0) and ((y2-y1)*(yp2-y1) >= 0) then
      begin
        r:=sqrt((x3-xp2)*(x3-xp2)+(y3-yp2)*(y3-yp2));
      end;
    end else begin
      r:=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
    end;
  end;
  write (r:0:3);
  Readln;
  CloseFile (inp);
end.
